package org.gd.rest.jersey.client;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;

import javax.ws.rs.core.MediaType;


public class JerseyClientGet {

    public static void main(String[] args) {
        try {
            Client client = Client.create();
            //WebResource webResource = client
            //.resource("http://localhost:8888/RESTfulExample/rest/json/metallica/get");
            WebResource webResource = client
                    .resource("http://localhost:8888/hello");

            ClientResponse response = webResource
                    .accept(MediaType.APPLICATION_JSON)
                    .get(ClientResponse.class);

            if (response.getStatus() != 200) {
                throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
            }
            String output = response.getEntity(String.class);
            System.out.println("Output from Server .... " + output);
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }
}
